<?php
	include ("controller.php");
	
//提交BUG 报告
if($action=='input'){
	//设置数据库
	$db  = new DBSQL($DB_Config);
	
	//设置数据库
	$tpl = new template($tpl_set);					//设置模板目录
	
	//释放系统设置
	@extract(sys_config());
	
	$error = 0;
	
	$username = trim($username);
	if(!$username){
		$error		= 1;
		msg('抱歉，请输入您的姓名');
	}
	
	$email = trim($email);
	if(!$email){
		$error		= 1;
		msg('抱歉，请输入您的Email');
	}
	
	if (!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$email) || strlen($email)>64) {
		$error		= 1;
		msg('抱歉，您输入的邮件不符合标准!');
	}	
	
	$softs = trim($softs);
	if(!$softs){
		$error		= 1;
		msg('抱歉，请输入使用的程序名');
	}
	
	$version = trim($version);
	if(!$version){
		$error		= 1;
		msg('抱歉，请输入使用的程序版本');
	}
	
	$question = trim($question);
	if(!$question){
		$error		= 1;
		msg('抱歉，请输入您的问题');
	}
	
	$details = trim($details);
	if(!$details){
		$error		= 1;
		msg('抱歉，请输入具体问题');
	}
	
	
	//没有错误写入数据库
	if($error == 0){
		//提交数据
		$data = array(
			'user'		=>$username,
			'email'		=>$email,
			'soft'		=>$softs,
			'version'	=>$version,
			'question'	=>$question,
			'detail'	=>$details,
			'postdate'	=>time(),
		);
		
		$check = array(
			'user'		=>$username,
			'email'		=>$email,
			'version'	=>$version,
			'question'	=>$question,
		);
		
		
		//重复效验
		if (is_array($check)){
			unset($k,$v);
			foreach ($check AS $k=>$v) {
				$w[] = "$k='$v'";
			}
			$ck = $db->rows("SELECT count(*) AS cnt FROM bug_list WHERE ".implode(' AND ',$w));
			
			//如果存在则提示
			if ($ck[cnt]>=1){
				msg('抱歉，您提交的问题已经存在，请等待站长答复!',$siteurl,5);
			}
		}
		
		//插入数据
		$db->insert('bug_list',$data);
		
		//发送邮件
		mails($mail_from,"SYSTN Bug ".$username." 提问!" ,"hi David: <br> 用户 <b><a href='mailto:$email'>$username</a></b> (".date('Y-m-d H:i').") 向您提出问题<br><br>$question<br><br>$details <br><br><a href='http://www.systn.com/admin.php'>点这里管理bug!</a>");
		
		msg('恭喜，您的BUG提交成功！系统会尽快通知相关人员检测或修复BUG！',$siteurl,5);
		
	}else{
		msg('抱歉，您提交数据错误!');
	}
}else{
	msg('抱歉，您访问页面错误。');
}
?>